package com.ghost.UI
{
	import com.ghost.model.UI_skin_data;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.media.SoundTransform;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;

	/**
	 * @author ghost
	 * 基础的文本
	 */
	public class Ghost_txt extends Sprite
	{
		private var scroll:Ghost_scroll;//滚动条
		private var txt:TextField;//文本
		private var txt_width:Number;//文本宽
		private var txt_height:Number;//文本高
		private var scroll_skin_v:Vector.<Object>;//滚动条skin皮肤数据
		/**
		 * @param width 宽度
		 * @param height 高度
		 * @param skin_v 滚动条皮肤
		 * @param size_bool 强制设置文本w h
		 */			
		public function Ghost_txt(width:Number=150,height:Number=100,skin_v:Vector.<Object>=null,size_bool:Boolean=false)
		{
			if(skin_v!=null)scroll_skin_v = skin_v;
			else scroll_skin_v = UI_skin_data.ghost_scroll_skin_v;
			txt_width = width;
			txt_height = height;
			txt = new TextField();
			this.addChild(txt);
			txt.wordWrap = true;
			if(size_bool==true)
			{
				txt.width = width;
				txt.height = height;
			}
		}
		public var scroll_bool:Boolean = true;
		/**
		 * @param textformat TextFormat 对象
		 * @param start_n 开始的索引位置
		 * @param end_n 结束的索引位置
		 */		
		public function setTextFormate(textformat:TextFormat,start_n:int=-1,end_n:int = -1):void
		{
			txt.setTextFormat(textformat,start_n,end_n);
		}
		/**
		 * @param value 颜色值
		 */		
		public function set textcolor(value:uint):void
		{
			txt.textColor = value;
		}
		/**
		 * @param str 设置普通文本数据
		 */		
		public function set text(str:String):void
		{
			txt.text = str;
			update();
		}
		public function get text():String
		{
			return txt.text;
		}
		/**
		 * @param str html数据格式文本
		 */		
		public function set htmlText(str:String):void
		{
			txt.htmlText = str;
			update();
		}
		/**
		 * @param bool 是否需要边框
		 */		
		public function set border(bool:Boolean):void
		{
			txt.border = bool;
		}
		/**
		 * @param bool 文本是否响应鼠标
		 */		
		public function set mouseEnabl(bool:Boolean):void
		{
			txt.mouseEnabled = bool;
		}
		/**
		 *设置文本对齐方式 
		 * @param type
		 */		
		public function set autoSize(type:String):void
		{
			txt.autoSize = type;
		}
		/**
		 *设置文本类型 
		 * @param type
		 */		
		public function set txt_type(type:String):void
		{
			txt.type = type;
		}
		/**
		 *文本是否可选 
		 * @param bool
		 */		
		public function set selectable(bool:Boolean):void
		{
			txt.selectable = bool;
		}
		/**
		 * @param bool 是否换行
		 */		
		public function set wordWrap(bool:Boolean):void
		{
			txt.wordWrap = bool;
		}
		/**
		 * @param bool 是否多行
		 */		
		public function set multiline(bool:Boolean):void
		{
			txt.multiline = bool;
		}
		/**
		 * @param h 文本高度
		 */		
		public function set txtheight(h:Number):void
		{
			txt.height = h;
			//this.height = h;
		}
		/**
		 * @param w 文本宽度
		 */		
		public function set txtwidth(w:Number):void
		{
			txt.width = w;
			//this.width = w;
		}
		/**
		 * 设置文字滤镜
		 * @param arr 滤镜数组
		 */		
		public function set txtfilters(arr:Array):void
		{
			txt.filters = arr;
		}
		/**
		 *更新滚动条
		 */		
		public function update():void
		{
			if(scroll_bool)
			{
				var text_height:Number = txt.textHeight;
				if(text_height>txt_height)
				{
					if(scroll)scroll.visible = true;
					else
					{
						scroll = new Ghost_scroll(scroll_skin_v);
						this.addChild(scroll);
					}
					scroll.height = txt_height;
					scroll.scrollTarget = txt;
					scroll.move(txt.x+txt.width,txt.y);
					scroll.update();
				}
				else
				{
					if(scroll != null)
					{
						scroll.visible = false;
					}
				}
			}
			else
			{
				txt.width = txt.textWidth+5;
				txt.height = txt.textHeight;
			}
		}
	}
}